﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;
using Common.Logging;
using Jackie.Utility.Notify.Contracts;
using Jackie.Utility.Notify.Domain;

namespace Jackie.Utility.Notify.Client
{
    public partial class MessageTitleForm : Form
    {
        private readonly ChannelFactory<IPublish> channelFactory;
        private readonly IPublish clientProxy;
        private readonly ILog logger;

        public MessageTitleForm()
        {
            InitializeComponent();
            logger = LogManager.GetLogger(GetType());
            try
            {
                channelFactory = new ChannelFactory<IPublish>("PublishService");
                clientProxy = channelFactory.CreateChannel();
            }
            catch (Exception ex)
            {
                logger.Error("error!", ex);
            }

        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                var title = new TitleInfo()
                                {
                                    Code = txtCode.Text,
                                    Discription = txtDiscription.Text,
                                    Name = txtName.Text,
                                    InstantMessage = cbInstantMessage.Checked
                                };
                clientProxy.RegisteredTitle(title);
            }
            catch (Exception ex)
            {
                logger.Error("error!", ex);
                MessageBox.Show(ex.Message);
            }

        }
    }
}
